package gui.server;

import gui.MenuName;
import gui.server.listener.ServerMenuEventListenr;

import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class ServerMenuBar extends JMenuBar{

	JMenu server;
	JMenu account;
	JMenu dataManager;
	JMenu about;
	ActionListener menuListenr;
	public ServerMenuBar(){

		initMenus();

		this.add(server);
		this.add(account);
		this.add(dataManager);
		this.add(about);


	}



	private void initMenus(){
		menuListenr = new ServerMenuEventListenr();
		initServerMenu();
		initAccountMenu();
		initDataMenu();
		initAboutMenu();
	}

	private void initServerMenu(){
		server=new JMenu(MenuName.SERVER);
		JMenuItem start=new JMenuItem(MenuName.START);
		JMenuItem stop=new JMenuItem(MenuName.STOP);
		JMenuItem log=new JMenuItem(MenuName.VIEW_LOG);
		JMenuItem exit=new JMenuItem(MenuName.EXIT);
		JMenuItem connect=new JMenuItem(MenuName.CONNECT);
		start.addActionListener(menuListenr);
		stop.addActionListener(menuListenr);
		log.addActionListener(menuListenr);
		exit.addActionListener(menuListenr);
		connect.addActionListener(menuListenr);
		server.add(connect);
		server.addSeparator();
		server.add(start);
		server.add(stop);
		server.add(log);
		server.addSeparator();
		server.add(exit);

	}

	private void initAccountMenu(){
		account=new JMenu(MenuName.ACCOUT);
		JMenuItem login=new JMenuItem(MenuName.LOGIN);
		JMenuItem logout=new JMenuItem(MenuName.LOGOUT);
		JMenuItem showMain=new JMenuItem(MenuName.LOGOUT);
		login.addActionListener(menuListenr);
		logout.addActionListener(menuListenr);
		account.add(login);
		account.add(logout);
	}

	private void initDataMenu(){
		dataManager=new JMenu(MenuName.DATA_MGR);
		JMenuItem userManager=new JMenuItem(MenuName.USR_MGR);
		JMenuItem groupManager=new JMenuItem(MenuName.GUP_MGR);
		userManager.addActionListener(menuListenr);
		groupManager.addActionListener(menuListenr);
		dataManager.add(userManager);
		dataManager.addSeparator();
		dataManager.add(groupManager);
	}

	private void initAboutMenu(){
		about=new JMenu(MenuName.ABOUT);
		JMenuItem help=new JMenuItem(MenuName.HELP);
		JMenuItem info=new JMenuItem(MenuName.INFO);

		help.addActionListener(menuListenr);
		info.addActionListener(menuListenr);

		about.add(help);
		about.add(info);
	}
}
